# Copyright (c) 2025 Bytedance Ltd. and/or its affiliates
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from utils import PREPROCESSORS, get_logger


class BaseModel:
    def __init__(self, model_name, **kwargs):
        self.model_name = model_name
        self.kwargs = kwargs
        self.logger = get_logger(self.__class__.__name__)
        self.preprocessors_cfg = kwargs.get("preprocessors", [])
        self.preprocessors = []
        self._load_preprocessors()

    def _load_preprocessors(self):
        for preprocessor_cfg in self.preprocessors_cfg:
            preprocessor_name = preprocessor_cfg["name"]
            preprocessor_kwargs = preprocessor_cfg.get("kwargs", {})
            preprocessor_build_cfg = {
                "type": preprocessor_name,
            }
            preprocessor_build_cfg.update(preprocessor_kwargs)
            preprocessor = PREPROCESSORS.build(preprocessor_build_cfg)
            self.preprocessors.append(preprocessor)

    def _preprocess_row_data(self, row_data):
        for preprocessor in self.preprocessors:
            row_data = preprocessor.preprocess(row_data)
        return row_data

    def infer(self, data):
        raise NotImplementedError
